import { NgModule } from '@angular/core';
import { NavigationEnd, Router, RouterModule } from '@angular/router';

@NgModule({
    imports: [
        RouterModule.forChild([
            {
                path: '',
                children: [
                    {
                        path: 'users',
                        loadChildren: () => import('./users/users.module').then(m => m.UsersModule),
                        data: { permission: 'Pages.Administration.Users' }
                    },
                    {
                        path: 'roles',
                        loadChildren: () => import('./roles/roles.module').then(m => m.RolesModule),
                        data: { permission: 'Pages.Administration.Roles' }
                    },
                    {
                        path: 'auditLogs',
                        loadChildren: () => import('./audit-logs/audit-logs.module').then(m => m.AuditLogsModule),
                        data: { permission: 'Pages.Administration.AuditLogs' }
                    },
                    {
                        path: 'maintenance',
                        loadChildren: () => import('./maintenance/maintenance.module').then(m => m.MaintenanceModule),
                        data: { permission: 'Pages.Administration.Host.Maintenance' }
                    },
                    {
                        path: 'hostSettings',
                        loadChildren: () => import('./settings/host-settings.module').then(m => m.HostSettingsModule),
                        data: { permission: 'Pages.Administration.Host.Settings' }
                    },
                    {
                        path: 'editions',
                        loadChildren: () => import('./editions/editions.module').then(m => m.EditionsModule),
                        data: { permission: 'Pages.Editions' }
                    },
                    {
                        path: 'languages',
                        loadChildren: () => import('./languages/languages.module').then(m => m.LanguagesModule),
                        data: { permission: 'Pages.Administration.Languages' }
                    },
                    {
                        path: 'languages/:name/texts',
                        loadChildren: () => import('./languages/language-texts.module').then(m => m.LanguageTextsModule),
                        data: { permission: 'Pages.Administration.Languages.ChangeTexts' }
                    },
                    {
                        path: 'tenants',
                        loadChildren: () => import('./tenants/tenants.module').then(m => m.TenantsModule),
                        data: { permission: 'Pages.Tenants' }
                    },
                    {
                        path: 'organization-units',
                        loadChildren: () => import('./organization-units/organization-units.module').then(m => m.OrganizationUnitsModule),
                        data: { permission: 'Pages.Administration.OrganizationUnits' }
                    },
                    {
                        path: 'tenantSettings',
                        loadChildren: () => import('./settings/tenant-settings.module').then(m => m.TenantSettingsModule),
                        data: { permission: 'Pages.Administration.Tenant.Settings' }
                    },
                    {
                        path: 'hostDashboard',
                        loadChildren: () => import('./dashboard/host-dashboard.module').then(m => m.HostDashboardModule),
                        data: { permission: 'Pages.Administration.Host.Dashboard' }
                    },
                    {
                        path: 'workFlowCategory',
                        loadChildren: () => import('./workFlowDesign/work-flow-category.module').then(m => m.WorkFlowCategoryModule),
                        data:{permission:''}
                    },
                    {
                        path: 'workFlowDesign',
                        loadChildren: () => import('./workFlowDesign/work-flow-design.module').then(m => m.WorkFlowDesignModule),
                        data:{permission:''}
                    },
                    {
                        path: 'workFlowManager',
                        loadChildren: () => import('./workFlowManger/workflow-manager.module').then(m => m.WorkflowManagerModule),
                        data:{permission:''}
                    },
                    {
                        path: 'login-attempts',
                        loadChildren: () => import('./login-attempts/login-attempts.module').then(m => m.LoginAttemptsModule),
                        data: {  }
                    },
                    {
                        path: 'menus',
                        loadChildren: () => import('./menus/menus.module').then(m => m.MenusModule),
                        data: { permission: 'Pages.Tenant.Menus' }
                    },
                    {
                        path: 'backendPage',
                        loadChildren: () => import('./backendPage/backendPage.module').then(m => m.BackendPageModule),
                        data: { permission: 'Pages.Administration.BackendPage' }
                    },
                    {
                        path: 'customConfig',
                        loadChildren: () => import('./customConfig/customConfig.module').then(m => m.CustomConfigModule),
                        data: { permission: 'Pages.Administration.CustomConfigs' }
                    },
                    {
                        path: 'frontendPage',
                        loadChildren: () => import('./frontendPage/frontendPage.module').then(m => m.FrontendPageModule),
                        data: { permission: 'Pages.Administration.FrontendPage' }
                    },
                    {
                        path: 'staticPages',
                        loadChildren: () => import('./staticPages/staticPages.module').then(m => m.StaticPagesModule),
                        data: { permission: 'Pages_StaticPages' }
                    },
                    {
                        path: 'taxonomy',
                        loadChildren: () => import('./taxonomy/taxonomy.module').then(m => m.TaxonomyModule),
                        data: { permission: 'Pages_Manage_Taxonomy' }
                    },
                    {
                        path: 'badWords',
                        loadChildren: () => import('./bad-words/bad-words.module').then(m => m.BadWordsModule),
                        data: { permission: 'Pages.BadWords' }
                    },
                    {
                        path: 'sitemap',
                        loadChildren: () => import('./sitemap/sitemap.module').then(m => m.SitemapModule),
                        data: { permission: 'Pages_Manage_SiteMap' }
                    },
                    {
                        path: 'robots-txt',
                        loadChildren: () => import('./robots-txt/robots-txt.module').then(m => m.RobotsTxtModule),
                        data: { permission: 'Pages_Manage_Robots' }
                    },
                    { path: '', redirectTo: 'hostDashboard', pathMatch: 'full' },
                    { path: '**', redirectTo: 'hostDashboard' }
                ]
            }
        ])
    ],
    exports: [
        RouterModule
    ]
})
export class AdminRoutingModule {

    constructor(
        private router: Router
    ) {
        router.events.subscribe((event) => {
            if (event instanceof NavigationEnd) {
                window.scroll(0, 0);
            }
        });
    }
}
